﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Genuilder.Extensibility
{
	public class ProjectInfo
	{
		public ProjectInfo(string path)
		{
			Path = path;
		}
		public string Path
		{
			get;
			private set;
		}
		public string RootNamespace
		{
			get
			{
				return GetProperty("RootNamespace");
			}
		}
		public string AssemblyName
		{
			get
			{
				return GetProperty("AssemblyName");
			}
		}

		Microsoft.Build.Evaluation.Project _Project;
		public Microsoft.Build.Evaluation.Project MsBuildProject
		{
			get
			{
				if(_Project == null)
				{
					_Project = new Microsoft.Build.Evaluation.Project(Path, null, null, new Microsoft.Build.Evaluation.ProjectCollection());
				}
				return _Project;
			}
		}

		Dictionary<string, string> _PropertiesCache = new Dictionary<string, string>();
		private string GetProperty(string property)
		{
			if(_PropertiesCache.ContainsKey(property))
				return _PropertiesCache[property];
			var result = MsBuildProject.GetProperty(property).EvaluatedValue;
			_PropertiesCache.Add(property, result);
			return result;
		}
	}
}
